<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
(function(){
	//更改底部工具栏 getPager返回页面对象
	var pager = $('#toolbar').datagrid('getPager');	
	  pager.pagination({
		pageList: [10,20,30],
	});
})
//显示添加车辆信息框
function addroute(){
	$("#dlg").dialog("open").dialog('setTitle', '添加车辆信息');
	    $('#dlg').form('clear');	
	    $('#routeupdate').hide();
	    $('#routeadd').show();
	    $('#rrid').hide();
	    $('#lab').hide();
}
//确认添加车辆信息
function routeadd(){
//获得新增窗口内输入的文本框的值
var route = new Object();
route.rname = $("#rname").val(); 
route.rstart = $("#rstart").combobox('getValue');
route.rend = $("#rend").combobox('getValue');
var json = JSON.stringify(route);
//通过ajax请求将对应数据发送到后台中
$.ajax({
	type:"post",
	url:"${pageContext.request.contextPath}/route/route_addRouteMsg.action",
	data:{"json":json},
	dataType:"text",
	success:function(data){
			$.messager.alert('提示','添加成功','info',function(){
				//刷新页面，关闭窗口，清除表单内容
				$("#RouteList").datagrid('reload');
				$('#dlg').dialog('close');
				$('#dlg').form('clear');	
			});
		}
	})
};
//删除用户信息
function deleteroute(){
	//获取被选中需要删除的数据
	 var data = $("#RouteList").datagrid('getSelections');
	 if(data.length==0){
		 $.messager.show({
				title:'警告',
				msg:'请选中需要删除的数据',
				timeout:1000,
				showType:'slide',
			    style:{
						top:'100',						
					}
			});
	 }else{
	      //声明一个空的数组 装选中的rid
	      var rids = [];
	      for (var i = 0; i < data.length; i++) {
			rids.push(data[i].rid);
		}
	$.messager.confirm('确认对话框', '您确认删除选中的'+data.length+'条数据吗？', function(r){
	    		if (r){
	    		    //通过ajax请求将对应数据发送到后台中
	    		    $.ajax({
	    		    	type:"post",
	    		    	url:'${pageContext.request.contextPath}/route/route_deleteRouteMsg.action',
	    		    	data:{"rids":rids},
	    		    	dataType:"text",
	    		    	success:function(data){
	    		    			//提示删除成功
	    		    			$.messager.alert('提示','删除成功','info',function(){
	    		    			$("#RouteList").datagrid('reload');
	    		    			$("#RouteList").datagrid('uncheckAll');
	    		    });
	    		}
	    		});
	         }
     });
  }
 }
//修改用户信息
function updateroute(){
	 var data = $("#RouteList").datagrid('getSelections');	
		if(data.length==0){
			$.messager.show({
				title:'警告',
				msg:'请选中需要修改的数据',
				timeout:1500,
				showType:'slide',
					style:{
						left:100,
						right:'',
						top:100
					}
		  		});
		}else if(data.length!=1){
			$.messager.show({
				title:'警告',
				msg:'你只能选择一条数据修改',
				timeout:1500,
				showType:'slide',
					style:{
						left:100,
						right:'',
						top:100
					}
		  		});
		}else{
			var route =$("#RouteList").datagrid('getSelected');
			$("#rid").textbox('setValue',route.rid)
			$("#rname").textbox('setValue',route.rname)
			$("#rstart").textbox('setValue',route.rstart);
			$("#rend").textbox('setValue',route.rend);
			$('#dlg').dialog('open').dialog('center').dialog('setTitle','修改信息');
			   //隐藏添加按钮
			   $('#routeadd').hide();
			   //隐藏id框和显示提醒框
			   $('#rrid').hide();
			   $('#lab').show();
			   //显示确认按钮
			    $('#routeupdate').show();		    
		}
		
 }	
 //确认修改用户信息
 function routeupdate(){
	 //获得新增窗口内输入的文本框的值
	 var route = new Object();
	 route.rid = $("#rid").val();
	 route.rname = $("#rname").val(); 
	 route.rstart = $("#rstart").combobox('getValue');
	 route.rend = $("#rend").combobox('getValue');
	 var json1 = JSON.stringify(route);
		$.ajax({	   				
				type:"post",			                                               
				url:"${pageContext.request.contextPath}/route/route_updateRouteMsg.action",
				data:{"json1":json1},
				dataType:"text",
				success:function(data){
					$.messager.alert('提示','修改成功', data)
				  //刷新页面，关闭窗口，清除表单内容
					$("#RouteList").datagrid('reload');
					$('#dlg').dialog('close');
					$('#dlg').form('clear');	
				}
		})
 }
</script>
<body>
 <table id="RouteList"  class="easyui-datagrid"
            toolbar="#toolbar" pagination="true" fit="true" 
            url="${pageContext.request.contextPath}/route/route_showRouteMsg.action" striped="true"
            rownumbers="true" fitColumns="true" border="false">
        <thead>
            <tr>
                <th field="ck" checkbox=true></th>
                <th field="rid"  hidden="true" >路线ID</th>
                <th field="rname" width='50' resizable='false' >路线名称</th>
                <th field="rstart" width='50' resizable='false'>路线起点</th>
                <th field="rend" width='50' resizable='false'>路线终点</th>
            </tr>
        </thead>
        <div id="toolbar">
        		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add"  plain="true"  onclick="addroute()">增加</a>
        		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit"  plain="true"  onclick="updateroute()">修改</a>
        		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove"  plain="true"  onclick="deleteroute()">删除</a>
   		 </div>
   		   <div id="dlg" class="easyui-dialog" 
style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle" id="">路线信息</div>
        <form id="fm" method="post" novalidate>
        <div class="fitem" id="routeid"> 
          <div class="fitem" id="rrid">
                <label>路线ID:</label>
                <input id="rid" name="rid" class="easyui-textbox" required="true">
            </div>
            <div class="fitem">
                <label>路线名称:</label>
                <input id="rname" name="cname" class="easyui-textbox" required="true" >
            </div>
            <div class="fitem">
                <label>路线起点:</label>
               <input id="rstart" class="easyui-combobox" name="rstart"
    			data-options="editable:false,valueField:'id',textField:'text',url:'${pageContext.request.contextPath}/route/route_findRstartMsg.action'" />    
            </div>
             <div class="fitem">
                <label>路线终点:</label>
                <input id="rend" class="easyui-combobox" name="rend"
    			data-options="editable:false,valueField:'id',textField:'text',url:'${pageContext.request.contextPath}/route/route_findRendMsg.action'" />        
            </div>
            <div class="fitem" id="lab">
                <label> 注：每次修改都需重新设置路线起点、终点</label>
            </div>
          </div>
        </form>
    </div>
    <div id="dlg-buttons">
    	<a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" 
style="width:90px" onclick="routeupdate()" id="routeupdate">确认修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" 
onclick="routeadd()" style="width:90px" id="routeadd" >确认添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" 
onclick="javascript:$('#dlg').dialog('close')" id="et" style="width:90px">取消</a>
    </div>
</body>
</html>